package com.apes.fn.rpt.profit.grossProfitProcess.processor;

import com.apes.fn.rpt.profit.grossProfitProcess.CommonGrossProfitProcess;
import com.apes.fn.rpt.profit.grossProfitProcess.GrossProfitProcess;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 会员储值消费
 */
@Component
public class VipCardUseExpense extends CommonGrossProfitProcess implements GrossProfitProcess {

    @Override
    public String getSQL(Date taskDate){

        return " select CREATE_DATE,\n" +
                "             INCOME_CATEGORIES,\n" +
                "             SERVE_TYPE_NAME,\n" +
                "             DEPT_ID,\n" +
                "             COMPANY_ID,\n" +
                "             SUM(AMOUNT) AMOUNT,\n" +
                "             SUM(TIMES) TIMES,\n" +
                "             SUM(PRICE_TOTAL) PRICE_TOTAL,\n" +
                "             SUM(vip_in) vip_in,\n" +
                "             SUM(vip_out) vip_out,\n" +
                "             SUM(COST) COST,\n" +
                "             SUM(CONSUMABLE_USE) CONSUMABLE_USE,\n" +
                "             SUM(ACCESSORY_COST) ACCESSORY_COST,\n" +
                "             SUM(MAN_HOUR_COST) MAN_HOUR_COST,\n" +
                "             SUM(PLATFORM_MANAGEMENT_FEE) PLATFORM_MANAGEMENT_FEE,\n" +
                "             SUM(SUPPLY_CHAIN_MANAGEMENT_FEE) SUPPLY_CHAIN_MANAGEMENT_FEE\n" +
                "      from (SELECT TRUNC(X.CREATE_DATE)           CREATE_DATE,\n" +
                "                   '预收'                           INCOME_CATEGORIES,\n" +
                "                   '会员储值消费'                       SERVE_TYPE_NAME,\n" +
                "                   X.DEPT_ID,\n" +
                "                   X.COMPANY_ID,\n" +
                "                   SUM(X.AMOUNT)                  AMOUNT,\n" +
                "                   0                              TIMES,\n" +
                "                   SUM(X.AMOUNT)                  PRICE_TOTAL,\n" +
                "                   0                              vip_in,\n" +
                "                   0                              vip_out,\n" +
                "                   0                              COST,\n" +
                "                   0                              CONSUMABLE_USE,\n" +
                "                   0                              ACCESSORY_COST,\n" +
                "                   0                              MAN_HOUR_COST,\n" +
                "                   SUM(X.PLATFORM_MANAGEMENT_FEE) PLATFORM_MANAGEMENT_FEE,\n" +
                "                   0                              SUPPLY_CHAIN_MANAGEMENT_FEE\n" +
                "            FROM (SELECT TRUNC(A.DATE_APPROVE) CREATE_DATE,\n" +
                "                         A.ID,\n" +
                "                         -1 * B.AMOUNT         AMOUNT,\n" +
                "                         A.DEPT_ID,\n" +
                "                         A.COMPANY_ID,\n" +
                "                         B.PLATFORM_MANAGEMENT_FEE\n" +
                "                  FROM RETAIL_ORDER A,\n" +
                "                       RETAIL_ORDER_PAYMENT_METHOD B\n" +
                "                  WHERE A.ID = B.RETAIL_ORDER_ID\n" +
                "                    AND PAYMENT_METHOD_TYPE IN ('05', '12')\n" +
                "                    AND A.DATE_APPROVE >= to_date(:P_DATE, 'YYYY-mm-dd')\n" +
                "                    AND A.DATE_APPROVE < to_date(:P_DATE, 'YYYY-mm-dd') + 1) X\n" +
                "            GROUP BY X.CREATE_DATE, X.DEPT_ID, X.COMPANY_ID\n" +
                "            union all\n" +
                "            SELECT TRUNC(X.CREATE_DATE)\n" +
                "                                                  CREATE_DATE,\n" +
                "                   '预收'                           INCOME_CATEGORIES,\n" +
                "                   '会员储值消费'                       SERVE_TYPE_NAME,\n" +
                "                   X.DEPT_ID,\n" +
                "                   X.COMPANY_ID,\n" +
                "                   SUM(X.AMOUNT)\n" +
                "                                                  AMOUNT,\n" +
                "                   0                              TIMES,\n" +
                "                   SUM(X.AMOUNT)                  PRICE_TOTAL,\n" +
                "                   0                              vip_in,\n" +
                "                   0                              vip_out,\n" +
                "                   0                              COST,\n" +
                "                   0                              CONSUMABLE_USE,\n" +
                "                   0                              ACCESSORY_COST,\n" +
                "                   0                              MAN_HOUR_COST,\n" +
                "                   SUM(X.PLATFORM_MANAGEMENT_FEE) PLATFORM_MANAGEMENT_FEE,\n" +
                "                   0                              SUPPLY_CHAIN_MANAGEMENT_FEE\n" +
                "            FROM (SELECT TRUNC(A.DATE_APPROVE)\n" +
                "                                       CREATE_DATE,\n" +
                "                         A.ID,\n" +
                "                         -1 * B.AMOUNT AMOUNT,\n" +
                "                         A.DEPT_ID,\n" +
                "                         A.COMPANY_ID,\n" +
                "                         B.PLATFORM_MANAGEMENT_FEE\n" +
                "                  FROM ADVANCE_PAYMENT A,\n" +
                "                       ADVANCE_PAYMENT_METHOD B\n" +
                "                  WHERE A.ID = B.PAYMENT_ID\n" +
                "                    AND PAYMENT_METHOD_TYPE\n" +
                "                      IN ('05', '12')\n" +
                "                    AND A.DATE_APPROVE >= to_date(:P_DATE, 'YYYY-mm-dd')\n" +
                "                    AND A.DATE_APPROVE\n" +
                "                      < to_date(:P_DATE, 'YYYY-mm-dd') + 1) X\n" +
                "            GROUP BY X.CREATE_DATE, X.DEPT_ID, X.COMPANY_ID) X\n" +
                "      group by CREATE_DATE, DEPT_ID, COMPANY_ID,INCOME_CATEGORIES,SERVE_TYPE_NAME";
    }

    @Override
    public boolean support(String type) {
        return "VipCardUse".equals(type);
    }
}
